package csc.fresher.finalgroupfour.controller;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Controller for home action.
 * 
 * @author tnguyen256
 *
 */
@Controller
public class HomeController {
		
	/**
	 * @param request
	 * @param userPrincipal
	 * @return
	 * Home action: if no user is logging in, return to login page. If yes, return home page.
	 */
	@RequestMapping(value = {"/", "home" })
	public ModelAndView home(HttpServletRequest request, Principal userPrincipal) {
		ModelAndView model = new ModelAndView();
		
		if (userPrincipal == null) {
			model.setViewName("login");
		} else {
			model.setViewName("home");
		}
		return model;
	}
}
